<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
 <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.7">
 <TITLE>SDCC Compiler User Guide: Pointers</TITLE>
 <LINK HREF="SDCCUdoc-8.html" REL=next>
 <LINK HREF="SDCCUdoc-6.html" REL=previous>
 <LINK HREF="SDCCUdoc.html#toc7" REL=contents>
</HEAD>
<BODY>
<A HREF="SDCCUdoc-8.html">Next</A>
<A HREF="SDCCUdoc-6.html">Previous</A>
<A HREF="SDCCUdoc.html#toc7">Contents</A>
<HR>
<H2><A NAME="Pointers"></A> <A NAME="s7">7. Pointers</A> </H2>

<P>SDCC allows (via language extensions) pointers to explicitly point to any
of the memory spaces of the 8051. In addition to the explicit pointers, the
compiler also allows a _generic class of pointers which can be used to point
to any of the memory spaces. 
<P>Pointer declaration examples.
<P>
<PRE>
/* pointer physically in xternal ram pointing to object in internal ram
 */ 
data unsigned char * xdata p;
/* pointer physically in code rom pointing to data in xdata space */ 
xdata
 unsigned char * code p;
/* pointer physically in code space pointing to data in code space */ 
code
 unsigned char * code p;

/* the folowing is a generic pointer physically located
 in xdata space */
char * xdata p;
 
</PRE>
<P>Well you get the idea. For compatibility with the previous version of the
compiler, the following syntax for pointer declaration is also supported. Note
the above examples will be portable to other commercially available compilers.
<P>
<PRE>
unsigned char _xdata *ucxdp; /* pointer to data in external ram */ 
unsigned
 char _data  *ucdp ; /* pointer to data in internal ram */ 
unsigned char _code
  *uccp ; /* pointer to data in R/O code space */
unsigned char _idata *uccp;
  /* pointer to upper 128 bytes of ram */
 
</PRE>
<P>All unqualified pointers are treated as 3 - byte '_generic' pointers. These
type of pointers can also to be explicitly declared.
<P>
<PRE>
unsigned char _generic *ucgp;
 
</PRE>
<P>The highest order byte of the generic pointers contains the data space
information. Assembler support routines are called whenever data is stored
or retrieved using _generic pointers. These are useful for developing reusable
library routines. Explicitly specifying the pointer type will generate the
most efficient code. Pointers declared using a mixture of OLD/NEW style could
have unpredictable results.
<HR>
<A HREF="SDCCUdoc-8.html">Next</A>
<A HREF="SDCCUdoc-6.html">Previous</A>
<A HREF="SDCCUdoc.html#toc7">Contents</A>
</BODY>
</HTML>
